home *** CD-ROM | disk | FTP | other *** search
- Path: ohstpy.mps.ohio-state.edu!vancleef
- From: vancleef@ohstpy.mps.ohio-state.edu
- Newsgroups: comp.lang.c++
- Subject: Re: Template Class Linkage?
- Message-ID: <1996Jan9.004515.8691@ohstpy>
- Date: 9 Jan 96 00:45:15 -0500
- References: <4cmnjs$mk7@mimsy.cs.umd.edu> <4cq4hs$raa@news2.deltanet.com> <4crpps$7ni@mimsy.cs.umd.edu>
- Organization: The Ohio State University, Department of Physics
-
- In article <4crpps$7ni@mimsy.cs.umd.edu>, gilman@cfar.umd.edu (Gil Carmel) writes:
- > Sergio Olivas (olivas@deltanet.com) wrote:
- >
- > : >I'm just learning templates, and I'm having problems with linkage.
- > : >When the template class member function bodies are included in the .h file,
- > : >everything is fine. But when the function bodies are in a separate .c file,
- > : >calls to these functions from other files give an "undefined reference to
- > : >function" error from the linker. Do template class member functions have
- > : >to be in the ".h" file, or is this a problem with my compiler?
- >
- > : Yes, this is a known 'feature' of C++ -- As far as the language
- > : standard and all the compilers go. I understand an update to the C++
- > : language will include some way of including the template stuff into
- > : the .c (cpp) files, as well as provide the Standard Template library
- > : as part of the language.
- >
- > : later,
- > : sergio
- >
- > Thanks. One more question:
- > What happens if two different files use the same template class function?
- > If both need to include the function body, then it will be defined twice and
- > the linker will produce an error.
-
- This works fine. I use templates all the time. Just remember
- that the template 'source code' must be included in
- the header file.
-
- -Garrett
-
-
-
- >
- > Gil
- >
- > --
- > |-----------------------------------------------------------|
- > | Gil Carmel | gilman@wam.umd.edu |
- > | Computer Science Undergraduate | gilman@cfar.umd.edu |
- > | University of Maryland | |
- > | College Park, MD | |
- > |-----------------------------------------------------------|
- > | | \o | |
- > | | |\ | |
- > | | / \ | |
-